import 'package:flutter/material.dart';
import '../public_keyBoardActions.dart';

class HLScrollView extends StatelessWidget {
  final EdgeInsetsGeometry? padding;
  final ScrollPhysics physics;
  final CrossAxisAlignment crossAxisAlignment;
  final MainAxisAlignment mainAxisAlignment;
  final ScrollController? controller;
  final List<Widget>? children;
  final Widget? child;
  final List<FocusNode>? nodeList;
  final bool tapOutsidedis;

  const HLScrollView({
    Key? key,
    this.child,
    this.children,
    this.padding,
    this.controller,
    this.physics = const BouncingScrollPhysics(),
    this.crossAxisAlignment = CrossAxisAlignment.start,
    this.mainAxisAlignment = MainAxisAlignment.start,
    this.tapOutsidedis = false,
    this.nodeList,
  })  : assert((child != null || children != null), "child和children不能同时为空"),
        super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget view = Container();
    if (child != null) {
      view = (padding != null) ? Padding(padding: padding!, child: child!) : child!;
    } else {
      ///  SingleChildScrollView
      view = SingleChildScrollView(
        padding: padding,
        physics: physics,
        controller: controller,
        child: Column(
          crossAxisAlignment: crossAxisAlignment,
          mainAxisAlignment: mainAxisAlignment,
          children: children!,
        ),
      );
    }

    ///键盘弹框
    if (nodeList != null) {
      view = HLKeyBoardActions.keyboardActionsWidget(
        list: nodeList!,
        child: view,
        tapOutsidedis: tapOutsidedis,
      );
    }
    return view;
  }
}
